package handler

import (
	"go_study/vidioWeb/common"
	"net/http"
)

func SetDefaultDual(r *common.DefinedRouter) {
	r.NotFound = DefaultFunc(func(response http.ResponseWriter, request *http.Request) {
		response.Write([]byte(`{"error":"NotFound"}`))
	})

	r.MethodNotAllowed = DefaultFunc(func(response http.ResponseWriter, request *http.Request) {
		response.Write([]byte(`{"error":"MethodNotAllowed"}`))
	})
}

type DefaultFunc func(http.ResponseWriter, *http.Request)

func (that DefaultFunc) ServeHTTP(response http.ResponseWriter, request *http.Request) {
	that(response, request)
}
